package com.huanwei.cc.db;

import android.content.Context;
import android.util.Log;

import com.j256.ormlite.dao.Dao;
import com.huanwei.cc.bean.Life_MSG3;


import java.util.List;


/**
 * Created by luoliwen on 16/4/28.
 * 完成对消息数据库的CRUD的操作
 */
public class Z_YHD_Dao {
    private Context context;
    private Dao<Life_MSG3, Integer> userDao;
    private Z_DataBaseHelper helper;

    public Z_YHD_Dao(Context context) {
        this.context = context;
        helper = Z_DataBaseHelper.getInstance(context);
        try {
            userDao = helper.getDao(Life_MSG3.class);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public void addMSG(String title ,String MSG, String Time


    ) {
        try {
            Life_MSG3 life_msg = new Life_MSG3();
            life_msg.setId(String.valueOf(Math.random()*10));
            life_msg.setTitle(title);
            life_msg.setMSG(MSG);
            life_msg.setTime(Time);
            userDao.create(life_msg);

        } catch (Exception e) {
            e.printStackTrace();
            Log.e("88888", "" + e);
        }
    }

    List<Life_MSG3> XTWUserInfos;

    public  List<Life_MSG3> query() {
        try {
            XTWUserInfos = userDao.queryForAll();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return XTWUserInfos;
    }

    public void deleteUser(Life_MSG3 user) {
        try {
            userDao.delete(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
